;
require([ 'suredyTreeSelector' ], function(TreeSelector) {
	$('.suredy-checker-img').on('click', function(event) {
		var $this = $(this);
		$this.attr('src', $this.attr('src') + '?_=' + (new Date().getTime()));
	});

	// init user tree
	TreeSelector('input#userName', Suredy.ctxp + '/config/ou/tree/true/true/true', {
		autoCollapse : false,
		style : 'department',
		showTitle : true,
		canFolderActive : false,
		size : 'lg',
		toggleActive : false
	});

	// 监听树的点击事件
	$('input#userName').on(TreeSelector.nodeClick, function() {
		if (!TreeSelector.isActive(this)) {
			$('input[name="userCode"]').val('');
			$('input#userName').val('');
			return false;
		}

		var userCode = TreeSelector.data(this, 'userCode');
		var name = TreeSelector.data(this, 'name');

		$('input[name="userCode"]').val(userCode);
		$('input#userName').val(name);

		TreeSelector.hidden(this);

		return true;

	});
});
